package org.cfg;

import com.sojoys.artifact.build.data.base.BaseCfg;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.tools.SK_String;
import com.xiaoleilu.hutool.util.StrUtil;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 召唤卡池
 */
public class SummonPoolCfg extends BaseCfg<SummonPoolCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "summon_pool";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.SummonPoolCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 8;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","池类型","权重","道具","品质","分数限制","分数","道具类型",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","poolType","weight","itemMap","quality","scoreLimit","score","type",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","poolType","weight","itemMap","quality","scoreLimit","score","type",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,635121014,-791592328,2116187465,651215103,1566009417,109264530,3575610,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","int[]","Map","int","int","int","int",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,int[].class,Map.class,Integer.class,Integer.class,Integer.class,Integer.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 池类型
	 */
	private int poolType;
	
	/**
	 * 权重
	 */
	private int[] weight;
	
	/**
	 * 道具
	 */
	private Map itemMap;
	
	/**
	 * 品质
	 */
	private int quality;
	
	/**
	 * 分数限制
	 */
	private int scoreLimit;
	
	/**
	 * 分数
	 */
	private int score;
	
	/**
	 * 道具类型
	 */
	private int type;
	
	
	
	public static SummonPoolCfg builder() {
		SummonPoolCfg summonPoolCfg = new SummonPoolCfg();
		return summonPoolCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 池类型
	 */
	public int getPoolType() {
		return poolType;
	}
	
	/**
	 * 权重
	 */
	public int[] getWeight() {
		return weight;
	}
	
	/**
	 * 道具
	 */
	public Map getItemMap() {
		return itemMap;
	}
	
	/**
	 * 品质
	 */
	public int getQuality() {
		return quality;
	}
	
	/**
	 * 分数限制
	 */
	public int getScoreLimit() {
		return scoreLimit;
	}
	
	/**
	 * 分数
	 */
	public int getScore() {
		return score;
	}
	
	/**
	 * 道具类型
	 */
	public int getType() {
		return type;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.poolType;
        values[2] = this.weight;
        values[3] = this.itemMap;
        values[4] = this.quality;
        values[5] = this.scoreLimit;
        values[6] = this.score;
        values[7] = this.type;
        return values;
	}
	
	protected SummonPoolCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.poolType = (int)vals[1];
		this.weight = (int[])vals[2];
		this.itemMap = (Map)vals[3];
		this.quality = (int)vals[4];
		this.scoreLimit = (int)vals[5];
		this.score = (int)vals[6];
		this.type = (int)vals[7];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.poolType);
        map.put(keys[2], this.weight);
        map.put(keys[3], this.itemMap);
        map.put(keys[4], this.quality);
        map.put(keys[5], this.scoreLimit);
        map.put(keys[6], this.score);
        map.put(keys[7], this.type);
        return map;
    }
    
    protected SummonPoolCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.poolType = (int)map.get(keys[1]);
   		this.weight = (int[])map.get(keys[2]);
   		this.itemMap = (Map)map.get(keys[3]);
   		this.quality = (int)map.get(keys[4]);
   		this.scoreLimit = (int)map.get(keys[5]);
   		this.score = (int)map.get(keys[6]);
   		this.type = (int)map.get(keys[7]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.poolType);
        obj.put(keys[2], this.weight);
        obj.put(keys[3], this.itemMap);
        obj.put(keys[4], this.quality);
        obj.put(keys[5], this.scoreLimit);
        obj.put(keys[6], this.score);
        obj.put(keys[7], this.type);
        return obj;
    }
    
    protected SummonPoolCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.poolType = obj.getIntValue(keys[1]);
		this.weight = obj.getObject(keys[2],int[].class);
		this.itemMap = obj.getObject(keys[3],Map.class);
	    this.quality = obj.getIntValue(keys[4]);
	    this.scoreLimit = obj.getIntValue(keys[5]);
	    this.score = obj.getIntValue(keys[6]);
	    this.type = obj.getIntValue(keys[7]);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.poolType);
	    byteBuf.writeObject(this.weight);
	    byteBuf.writeObject(this.itemMap);
	    byteBuf.writeInt(this.quality);
	    byteBuf.writeInt(this.scoreLimit);
	    byteBuf.writeInt(this.score);
	    byteBuf.writeInt(this.type);
    }
	
	protected SummonPoolCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.poolType = byteBuf.readInt(null);
	    this.weight = byteBuf.readIntArray(null);
	    this.itemMap = (Map)byteBuf.readObject();
	    this.quality = byteBuf.readInt(null);
	    this.scoreLimit = byteBuf.readInt(null);
	    this.score = byteBuf.readInt(null);
	    this.type = byteBuf.readInt(null);
	    return this;
	}
	
	public SummonPoolCfg deepCopy(){
		SummonPoolCfg summonPoolCfg = null;
		try {
			summonPoolCfg = (SummonPoolCfg) super.clone();
		    summonPoolCfg.weight = ToolCopy.copyObject(this.weight);
		    summonPoolCfg.itemMap = ToolCopy.copyObject(this.itemMap);
			return summonPoolCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return summonPoolCfg;
	}
//自定义内容起始位置
//自定义内容结束位置
}
